Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@glimmer/syntax
Advanced tools
@glimmer/syntax is a library for parsing, traversing, and transforming Glimmer templates. It provides tools to work with the syntax tree of Glimmer templates, which are used in Ember.js applications.
Parsing Templates
This feature allows you to parse a Glimmer template string into an Abstract Syntax Tree (AST). The `preprocess` function takes a template string and returns its AST representation.
const { preprocess } = require('@glimmer/syntax');
const template = '<div>{{hello}}</div>';
const ast = preprocess(template);
console.log(ast);
Traversing AST
This feature allows you to traverse the AST of a Glimmer template. The `traverse` function takes an AST and a visitor object, which defines the functions to be called for different node types.
const { traverse } = require('@glimmer/syntax');
const ast = preprocess('<div>{{hello}}</div>');
traverse(ast, {
MustacheStatement(node) {
console.log('Found a mustache statement:', node);
}
});
Transforming AST
This feature allows you to transform the AST of a Glimmer template. You can modify nodes in the AST and then convert it back to a template string using the `print` function.
const { preprocess, print, builders } = require('@glimmer/syntax');
let ast = preprocess('<div>{{hello}}</div>');
traverse(ast, {
MustacheStatement(node) {
node.path = builders.path('goodbye');
}
});
const transformedTemplate = print(ast);
console.log(transformedTemplate);
Handlebars is a popular templating engine that provides similar functionality for parsing, traversing, and transforming Handlebars templates. It is more general-purpose compared to @glimmer/syntax, which is specifically designed for Glimmer templates.
Esprima is a high-performance, standard-compliant ECMAScript parser. It provides similar functionality for parsing JavaScript code into an AST and traversing it. Like babel-parser, it is not specific to templates but is useful for general JavaScript code analysis and transformation.
FAQs
Unknown package
The npm package @glimmer/syntax receives a total of 215,364 weekly downloads. As such, @glimmer/syntax popularity was classified as popular.
We found that @glimmer/syntax demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 14 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.